﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;

namespace ADSync.ConfigurationComponent
{
	/// <summary>
	/// Class for configuration settings in Key/Value format
	/// </summary>
	public class EngineConfiguration
	{
		#region Preferences
		public Dictionary<String, String> KeyValue
		{
			get;
			set;
		}
		#endregion

		#region Constructors
		public EngineConfiguration( NameValueCollection ConfigurationKeyValueCollection )
		{
			this.KeyValue = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
			this.LoadConfiguration(ConfigurationKeyValueCollection);
		}
		#endregion

		#region Private Methods
		private void LoadConfiguration(NameValueCollection ConfigurationKeyValueCollection)
		{
			try
			{
				if (this.KeyValue.Count > 0) this.KeyValue.Clear();

				foreach (String KeyName in ConfigurationKeyValueCollection.AllKeys)
				{
					if (!this.KeyValue.ContainsKey(KeyName))
					{
						this.KeyValue.Add( KeyName, ConfigurationKeyValueCollection.Get(KeyName) );
					}
				}
			}
			catch (Exception eX)
			{
				throw new Exception(string.Format("{0}::{1}", new StackFrame(0, true).GetMethod().Name, eX.Message));
			}
		}
		#endregion
	}
}
